package io.noties.markwon.plugin.uml.model


class UmlClassAttribute : AdapterItem {
    //    **********************************************************************************************
    //    Getters and setters
    //    **********************************************************************************************
    override lateinit var name: String
    var attributeOrder: Int
    var visibility = Visibility.PRIVATE
    var isStatic = false
    var isFinal = false
    var umlType: UmlType? = null
    var typeMultiplicity = TypeMultiplicity.SINGLE
    var arrayDimension = 1 //only used if it's a table

    //    **********************************************************************************************
    //    Constructors
    //    **********************************************************************************************
    constructor(
        name: String,
        attributeOrder: Int,
        visibility: Visibility,
        aStatic: Boolean,
        aFinal: Boolean,
        umlType: UmlType?,
        typeMultiplicity: TypeMultiplicity,
        arrayDimension: Int
    ) {
        this.name = name
        this.attributeOrder = attributeOrder
        this.visibility = visibility
        isStatic = aStatic
        isFinal = aFinal
        this.umlType = umlType
        this.typeMultiplicity = typeMultiplicity
        this.arrayDimension = arrayDimension
    }

    constructor(attributeOrder: Int) {
        this.attributeOrder = attributeOrder
    }

    //return attribute name with conventional modifiers
    val attributeCompleteString: String
        get() {
            //return attribute name with conventional modifiers
            var completeString = String()
            completeString =
                when (visibility) {
                    Visibility.PUBLIC -> "+"
                    Visibility.PROTECTED -> "~"
                    else -> "-"
                }
            completeString =
                when (typeMultiplicity) {
                    TypeMultiplicity.COLLECTION -> completeString + name + " : <" + umlType!!.name + ">"
                    TypeMultiplicity.ARRAY -> completeString + name + " : [" + umlType!!.name + "]^" + arrayDimension
                    else -> completeString + name + " : " + umlType!!.name
                }
            return completeString
        }


    companion object {
        const val JSON_CLASS_ATTRIBUTE_NAME = "ClassAttributeName"
        const val JSON_CLASS_ATTRIBUTE_INDEX = "ClassAttributeIndex"
        const val JSON_CLASS_ATTRIBUTE_VISIBILITY = "ClassAttributeVisibility"
        const val JSON_CLASS_ATTRIBUTE_STATIC = "ClassAttributeStatic"
        const val JSON_CLASS_ATTRIBUTE_FINAL = "ClassAttributeFinal"
        const val JSON_CLASS_ATTRIBUTE_TYPE = "ClassAttributeType"
        const val JSON_CLASS_ATTRIBUTE_TYPE_MULTIPLICITY = "ClassAttributeTypeMultiplicity"
        const val JSON_CLASS_ATTRIBUTE_ARRAY_DIMENSION = "ClassAttributeArrayDimension"
        fun indexOf(attributeName: String, attributes: ArrayList<UmlClassAttribute>): Int {
            for (a in attributes) if (attributeName == a.name) return attributes.indexOf(a)
            return -1
        }
    }
}
